<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('发票稿件选择')" />
</head>
<body class="gray-bg">
<input id="invoiceId" name="invoiceId" th:value="${invoiceId}" type="hidden">
<input id="incomingId" name="incomingId" th:value="${incomingId}" type="hidden">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('work:paper:edit')}]];
        var removeFlag = [[${@permission.hasPermi('work:paper:remove')}]];
        var paperTypeDatas = [[${@dict.getType('work_paper_type')}]];
        var platformDatas = [[${@dict.getType('work_platform')}]];
        var priceTypeDatas = [[${@dict.getType('work_price_type')}]];
        var paperStatusDatas = [[${@dict.getType('work_paper_status')}]];
        var prefix = ctx + "work";


        $(function() {
            var options = {
                url: prefix + "/invoice/invoicecancel/"+$('#invoiceId').val(),
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sortName: "invoice_id",
                detailView: true,
                onExpandRow : function(index, row, $detail) {
                    initChildTable(index, row, $detail);
                },
                columns: [
                    {
                        field : 'invoiceId',
                        title : '发票ID'
                    },
                    {
                        field: 'invoicePrice',
                        title: '开票金额(不含税)',
                        align: 'center'
                    },
                    {
                        field: 'taxPoint',
                        title: '税点',
                        align: 'center',
                        formatter: function(value, row, index) {
                            return value+'%'
                        }

                    },{
                        field: 'customerName',
                        title: '客户名称',
                        align: 'center'
                    },{
                        field: 'companyName',
                        title: '公司名',
                        align: 'center'
                    },{
                        field: 'cost',
                        title: '成本',
                        align: 'center'
                    },{
                        field: 'actualPrice',
                        title: '实际价格',
                        align: 'center'
                    },{
                        field: 'counts',
                        title: '记录条数',
                        align: 'center'
                    }
                    ]
            };
            $.table.init(options);
        });
        var arr = [];
        initChildTable = function(index, row, $detail) {
            var childTable = $detail.html('<table></table>').find('table');
            $(childTable).bootstrapTable({
                url: prefix + "/paper/cancel/"+$('#incomingId').val()+"/"+$('#invoiceId').val(),
                id:'child-table',
                method: 'post',
                sidePagination: "server",
                contentType: "application/x-www-form-urlencoded",
                queryParams : {
                    invoiceId: row.invoiceId
                },
                onCheck: function (on) {
                    arr.push(on.paperId);
                }      ,               // 当选择此行时触发
                onUncheck: function (off) {
                    var i = arr.indexOf(off.paperId);
                    if(i>=0){
                        arr.splice(i,1);
                    }
                },
                onCheckAll: function (all) {
                    $.each(all,function (index,value){
                       arr.push(value.paperId);
                    })

                }               ,     // 当全选行时触发
                onUncheckAll: function () {
                    arr=[];
                },
                columns: [
                    {
                        checkbox:true,
                        formatter:function(value,row,index){

                            if (row.isCheck >0) { //根据行里字段判断是否选中
                                arr.push(row.paperId)
                                return {
                                    checked: true//设置选中
                                };
                            }
                            return value;
                        }

                    },
                    {
                    field: 'paperId',
                    title: '稿件ID'
                },
                    {
                        field: 'paperStatus',
                        title: '状态',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(paperStatusDatas, value);
                        }
                    },
                    {
                        field: 'paperType',
                        title: '稿件类型',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(paperTypeDatas, value);
                        }
                    },
                    {
                        field: 'paperName',
                        title: '稿件名称'
                    },
                    {
                        field: 'belong',
                        title: '稿件所属',
                        width: 80
                    },
                    {
                        field: 'customerName',
                        title: '客户名称'
                    },
                    {
                        field: 'companyName',
                        title: '客户所属公司'
                    },{
                        field: 'createTime',
                        title: '登记时间'
                    },
                    {
                        field: 'mediaName',
                        title: '媒体名称'
                    },
                    {
                        field: 'platform',
                        title: '平台',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(platformDatas, value);
                        }
                    },
                    {
                        field: 'mediaCreate',
                        title: '媒介'
                    },
                    {
                        field: 'publishLink',
                        title: '刊登链接'
                    },
                    {
                        field: 'publishDate',
                        title: '刊登时间'
                    },
                    {
                        field: 'paperPrice',
                        title: '稿件费'
                    },
                    {
                        field: 'flowPrice',
                        title: '刷量费'
                    },
                    {
                        field: 'cost',
                        title: '成本'
                    },
                    {
                        field: 'actualCost',
                        title: '实际成本'
                    },
                    {
                        field: 'price',
                        title: '单价'
                    },
                    {
                        field: 'words',
                        title: '字数'
                    },
                    {
                        field: 'actualPrice',
                        title: '实际总价'
                    },
                    {
                        field: 'priceType',
                        title: '价格类型',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(priceTypeDatas, value);
                        }
                    },
                    {
                        field: 'offAccountDate',
                        title: '销账时间'
                    },
                    {
                        field: 'commision',
                        title: '提成'
                    },
                    {
                        field: 'commisionDate',
                        title: '提成时间'
                    },
                    {
                        field: 'flowRemark',
                        title: '刷量备注'
                    },
                    {
                        field: 'originalLink',
                        title: '原始链接'
                    },
                    {
                        field: 'paybackPeriod',
                        title: '回款周期'
                    },
                    {
                        field: 'remark',
                        title: '备注'
                    }]
            });
        };
        /* 添加用户-选择用户-提交(回调形式-父页面调用子页面) */
        function getSelections() {

            return arr;
        }
    </script>

</body>
</html>